package com.gitee.lw114514.tliasweb.service.impl;

import com.gitee.lw114514.tliasweb.mapper.DeptMapper;
import com.gitee.lw114514.tliasweb.pojo.Dept;
import com.gitee.lw114514.tliasweb.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }

    @Override
    public void deleteById(int id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void add(Dept dept) {
        //1.补全基础属性：创建时间和修改时间
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        //2.插入部门
        deptMapper.insert(dept);
    }

    @Override
    public Dept getById(Integer  id) {
        return deptMapper.getById(id);
    }

    @Override
    public void update(Dept dept) {
        //1.补全基础属性：修改时间
        dept.setUpdateTime(LocalDateTime.now());

        //2.更新部门
        deptMapper.update(dept);

    }
}
